package util;

public class MyPage {
	int PageSize=10; //调用时可自定义变量，每页条数   
	int PageRows=8; //调用时可自定义变量，页码组，每组显示多少个页码编号，8默认，实际显示数会自动+1，包含当前页码   

	int RowCount=0;//总条数   
	int PageCount=1;//总页数    
	int inPage=1; //当前页码默认值   
	int inRow=0; //本页查询开始行号 默认 0   
	String linkPage = "?"; //调用时可以自定义变量，页码链接页面    
	String mce_href = ""; //超链接路径

	//显示文字 默认, 调用时可以自定义变量   
	String langs = "首页,上一页,下一页,尾页,共,条记录,页";   
	String[] langss= langs.split(",");   

	String lang_first_page = langss[0];   
	String lang_pre_page = langss[1];   
	String lang_next_page = langss[2];    
	String lang_end_page = langss[3];   
	String lang_total = langss[4];   
	String lang_record_number = langss[5];   
	String lang_page = langss[6];   

	//临时   
	String page="1";  

	//返回值，分页页码列表   
	String pagesInfo="";   


	/****  
	 * 主方法 获得 分页列表字符串  
	 * @return  
	 */  
	public String pageInfo(){    

		if(page!=null) inPage=Integer.parseInt(page);   

		if(inPage<1) inPage=1;   
		if(inPage>PageCount) inPage=PageCount;   
		inRow = (inPage-1)*PageSize; 

		//页码显示部分   
		int PageRowsL = PageRows/2; // 生成当前页码 左侧最大调用的页码数   
		int PageRowsR = PageRows-PageRows/2; // 生成当前页码 右侧最大调用的页码数   
		if(inPage<=PageRowsL){   
			PageRowsL = inPage-1;   
			PageRowsR = PageRows-inPage+1;   
		}   
		if(inPage+PageRowsR>PageCount){   
			PageRowsL = PageRows-(PageCount-inPage);   
			PageRowsR = PageCount-inPage;   
		}   

		int PageLs=1; //左侧开始最大页码号   
		int PageRs=PageCount; //左侧开始最大页码号    
		PageLs = ((inPage - PageRowsL)>=1)?inPage-PageRowsL:1;  //实际左侧第一个显示的页码   
		PageRs = ((inPage + PageRowsR)<=PageCount)?inPage+PageRowsR:PageCount; //实际右侧第一个显示的页码   


		pagesInfo = pagesInfo+("<div class=\"viciao\">");   

		//首页   
		pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page=1\">"+lang_first_page+"</a>");   
		//上一页
		if(page.equals("1")){
			pagesInfo = pagesInfo+("<span class=\"current\">"+lang_pre_page+"</span>");
		}else{
			pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page="+(inPage-1)+"\">"+lang_pre_page+"</a>");
		}

		//左侧页码   
		if(PageLs!=inPage){   
			for(int iL=PageLs;iL<inPage;iL++){   
				pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page="+iL+"\">"+iL+"</a>");   
			}   
		}   
		//当前页码   
		pagesInfo = pagesInfo+("<span class=\"current\">"+inPage+"</span>");   
		//右侧页码   
		if(PageRs!=inPage){   
			for(int iR=inPage+1;iR<=PageRs;iR++){   
				pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page="+iR+"\">"+iR+"</a>");   
			}   
		}   
		//下一页 
		if(page.equals(""+PageCount)){
			pagesInfo = pagesInfo+("<span class=\"current\">"+lang_next_page+"</span>");
		}else{
			pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page="+(inPage+1)+"\">"+lang_next_page+"</a>");
		}

		//尾页   
		pagesInfo = pagesInfo+("<a href=\""+mce_href+""+linkPage+"page="+PageCount+"\">"+lang_end_page+"</a>");   

		pagesInfo = pagesInfo+("<span class=\"current\">共"+RowCount+"条记录</span><span class=\"current\">"+page+"/"+PageCount+"页</span>");

		pagesInfo = pagesInfo+("</ul></div>");   


		return pagesInfo;   



	} 
	
	public void setPageSize(int PageSize){   
		this.PageSize = PageSize;   
	}   
	public int getPageSize(){   
		return PageSize;   
	} 

	public void setPage(String page){   
		this.page = page;   
	}   
	public String getPage(){   
		return page;   
	}  

	public void setLinkPage(String linkPage){   
		this.linkPage = linkPage;   
	}   
	public String getLinkPage(){   
		return linkPage;   
	}   


	  


	public void setRowCount(int RowCount){   
		this.RowCount = RowCount;   
	}   
	public int getRowCount(){   
		return RowCount;   
	}  

	public void setPageCount(int PageCount){   
		this.PageCount = PageCount;   
	}   
	public int getPageCount(){   
		return PageCount;   
	} 

	public void setPageRows(int PageRows){   
		this.PageRows = PageRows;   
	}   
	public int getPageRows(){   
		return PageRows;   
	}


	public void setLangs(String langs){   
		this.langs = langs;   
	}   
	public String getLangs(){   
		return langs;   
	}   


	public void setLang_first_page(String lang_first_page){   
		this.lang_first_page = lang_first_page;   
	}   
	public String getLang_first_page(){   
		return lang_first_page;   
	}   

	public void setLang_pre_page(String lang_pre_page){   
		this.lang_pre_page = lang_pre_page;   
	}   
	public String getLang_pre_page(){   
		return lang_pre_page;   
	}    

	public void setLang_next_page(String lang_next_page){   
		this.lang_next_page = lang_next_page;   
	}   
	public String getLang_next_page(){   
		return lang_next_page;   
	}      

	public void setLang_end_page(String lang_end_page){   
		this.lang_end_page = lang_end_page;   
	}   
	public String getLang_end_page(){   
		return lang_end_page;   
	}       

	public void setLang_total(String lang_total){   
		this.lang_total = lang_total;   
	}   
	public String getLang_total(){   
		return lang_total;   
	}       

	public void setLang_record_number(String lang_record_number){   
		this.lang_record_number = lang_record_number;   
	}   
	public String getLang_record_number(){   
		return lang_record_number;   
	}   

	public void setLang_page(String lang_page){   
		this.lang_page = lang_page;   
	}   
	public String getLang_page(){   
		return lang_page;   
	}
	public void SetMce_href(String mce_href){ 
		this.mce_href = mce_href;
	}   
	public String getMce_href(){   
		return mce_href;   
	}

}
